////////////////////////////////////////////////////////////////////////////////
//
//  Zemoga Inc
//  Copyright 2011 Zemoga Inc
//  All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////
package com.videojukebox.components
{
	import ca.newcommerce.youtube.data.ThumbnailData;
	
	import com.videojukebox.components.skins.VideoResultItemBase;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.events.ItemClickEvent;
	
	
	/**
	 * Class description here
	 * 
	 * @author	davidnino	<email>
	 */
	public class VideoResultItem extends VideoResultItemBase
	{
		//------------------------------------------------------------------------------
		//
		//  Constants
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		
		//------------------------------------------------------------------------------
		//
		//  Static Methods
		//
		//------------------------------------------------------------------------------
		
		////////////////////////////////////////////////////////////////////////////////
		//
		//  Constructor
		//
		////////////////////////////////////////////////////////////////////////////////
		
		public function VideoResultItem()
		{
			super();
		}
		
		//------------------------------------------------------------------------------
		//
		//  Variables
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		
		
		//------------------------------------------------------------------------------
		//
		//  Properties (getters/setters)
		//
		//------------------------------------------------------------------------------
		
		//------------------------------------------------------------------------------
		//
		//  Overriden methods
		//
		//------------------------------------------------------------------------------
		override protected function childrenCreated() : void
		{
			super.childrenCreated();
			addEventListeners();
		}
		
		override public function set data(value:Object):void
		{
			super.data = value;
			this.lb_videoName.text = data.title;
			
			
			var thumbnail:ThumbnailData = data.media.thumbnails.next();
			videoThumb.source = thumbnail.url;
		}
		//------------------------------------------------------------------------------
		//
		//  Methods
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		private function addEventListeners():void
		{
			addEventListener(Event.REMOVED_FROM_STAGE, removeFromStage_handler, false, 0, true);
			addEventListener(MouseEvent.CLICK, itemTitle_click_handler, false, 0, true);
		}
		
		private function removeEventListeners():void
		{
			removeEventListener(MouseEvent.CLICK, itemTitle_click_handler, false);
		}
		
		private function dispose(): void
		{
			removeEventListeners();
			removeAllElements();
		}
			
		//------------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//------------------------------------------------------------------------------
		protected function removeFromStage_handler(event:Event):void
		{
			dispose();
		}
		
		protected function itemTitle_click_handler(event:MouseEvent):void
		{
			var e:ItemClickEvent = new ItemClickEvent(ItemClickEvent.ITEM_CLICK, true);
			
			e.item = {"data":data};
			e.index = itemIndex;
			
			dispatchEvent(e);
		}
	}
}